/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hecatone;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import java.util.Hashtable;
import java.util.Enumeration;
import org.apache.log4j.Priority;
/**
 *
 * @author fredericpaquette
 */
public class Army  {
    private static final Logger logger = Logger.getLogger(Army.class);
    public int ID;
    public String COMMANDER;
    private Hashtable SQUADS;
    
    Army(Hashtable SQUADS, int ID){
        
        this.SQUADS = SQUADS;
        this.ID = ID;
        
        
        PropertyConfigurator.configure("log4j.properties");
        logger.debug("Army created:"+ this.ID);
    }
    
    public Enumeration getSquads()
    {
        Enumeration squads;
        
        squads = SQUADS.elements();
        return squads;
    }
    
//   This method return the army total attack strenght with no environment modifier.
//    This is useful to calculate the overun chances
    
    public int getArmyTotalAttack()
    {
        logger.debug("Entering getArmyStrenght");
        int attack = 0;
        Enumeration squads = getSquads();
        while(squads.hasMoreElements())
        {
            Squad sq = (Squad)squads.nextElement();
            attack = attack + sq.getSquadAttack();
        }
        logger.debug("Army attack = " + attack);
        return attack;
    }
    
    public int getArmyTotalConstitution()
    {
        logger.debug("Entering getArmyTotalConstitution");
        int defense = 0;
        Enumeration squads = getSquads();
        while(squads.hasMoreElements())
        {
            Squad sq = (Squad)squads.nextElement();
            defense = defense + sq.getSquadConstitution();
        }
        logger.debug("Army constitution is " + defense);
        return defense;
    }
}
